VERSION 0.7
FROM ../konfig-dash+build-konfig-dash
WORKDIR /konfig-integration-tests

integration-tests:
  COPY package.json yarn.lock logo.png .
  RUN yarn --frozen-lockfile
  COPY tsconfig.json vitest.config.ts util.ts .
  COPY sdks sdks
  COPY tests tests
  COPY apiServer.cjs .
  COPY scripts scripts
  RUN --secret AWS_ACCESS_KEY_ID --secret AWS_SECRET_ACCESS_KEY ./scripts/install-aws-cli.sh
  # can be overridden at runtime (e.g. "docker run konfig-integration-tests:latest --testName=TestName")
  ENTRYPOINT ["yarn", "test:ci"]
  CMD []
  SAVE IMAGE konfig-integration-tests:latest

test:
  FROM earthly/dind:alpine-3.18-docker-23.0.6-r4
  COPY compose/.env .
  COPY compose/compose.yaml .
  ARG TEST_ARGS
  WITH DOCKER \
        --compose compose.yaml \
        --load konfig-python-formatter:latest=../konfig-python-formatter-server-blackd+run-python-formatter \
        --load konfig-generator:latest=../konfig-generator-api+run-generator \
        --load konfig-api:latest=../konfig-dash+run-konfig-api \
        --load konfig-integration-tests:latest=+integration-tests
    RUN --secret NPM_TOKEN --secret GITHUB_ACTIONS docker run \
        --network="konfig-network" \
        -e "KONFIG_API_URL=http://konfig-api:8911" \
        -e "NPM_TOKEN=${NPM_TOKEN}" \
        -e "GITHUB_ACTIONS=${GITHUB_ACTIONS}" \
        konfig-integration-tests:latest $TEST_ARGS
  END

build-all:
  BUILD ../konfig-python-formatter-server-blackd+run-python-formatter
  BUILD ../konfig-generator-api+run-generator
  BUILD ../konfig-dash+run-konfig-api
  BUILD +integration-tests